<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit :isheader="isheader">
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
            <a-dropdown  style="margin-left:0px ">
                <a-menu slot="overlay"  @click="selectItem">
                  <a-menu-item key="1">{{i18n('list.addUserAttr','新增用户属性')}}</a-menu-item>
                  <a-menu-item key="0">{{i18n('list.addOrganDimAttr','新增组织维度属性')}}</a-menu-item>
                </a-menu>
                <a-button  :show-no-right="true" style="margin-left: 8px" type="primary">{{$ti18('rxList.newBtn','新建')}}<a-icon type="down" /> </a-button>
              </a-dropdown>
              <a-dropdown v-if="removeEnable && selectedRowKeys.length > 0">
                  <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}</a-button>
              </a-dropdown>
          </div>
           <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
        </div>
        <div btnalign="right"  slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel"  @close="closeSearchbar">
          <a-form :layout="colLayout">
            <a-row :gutter="24">
              <a-col :span="colSpan">
             <a-form-item :label="i18n('form.groupName','分组名称')">
                          <a-input :placeholder="i18n('form.groupName','分组名称','input')" v-model="queryParam['Q_opg.NAME__S_LK']"/>
             </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <rx-grid
                ref="table"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :bordered="isBorder"
                :defaultPageSize="10"
                url="/api-user/user/org/osPropertiesGroup/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                @selectChange="onSelectChange"
        >
          <span slot="enabled" slot-scope="{text,record, index}">

               <a-tag :color="statusMap[text].color">
                        <span>{{ statusMap[text].text }}</span>
               </a-tag>
          </span>
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span v-if="editEnable && showBtn(false)" @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
            <span v-if="removeEnable && showBtn(false)" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import osPropertiesGroupApi from '@/api/user/org/osPropertiesGroup'
  import osPropertiesGroupEdit from './OsPropertiesGroupEdit'
  import {BaseList,Util} from "@lowcode/jpaas-common-lib";
  export default {
    name: 'osPropertiesGroupList',
    mixins: [BaseList],
    data() {
      return {
        isGroup:false,
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 60,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('form.groupName','分组名称'), dataIndex: 'name', width: 100},
          {title: this.i18n('form.enabledOrNot','是否启用'), dataIndex: 'enabled', width: 100,scopedSlots: {customRender: 'enabled'}},
          {title: this.i18n('form.dimension','维度'), dataIndex: 'dimName', width: 100},
          {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', sorter: true, sortField: 'CREATE_TIME_', width: 120},
          {title: this.$ti18('rxList.action','操作'), width: 60, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],

        statusMap: {
              "yes": {color: 'green', text: this.i18n('yes','是')},
              "no": {color: 'red', text: this.i18n('no','否')},

        },
        queryParam:{},
        component:osPropertiesGroupEdit,
        comment:this.i18n('list.customAttrGroup','自定义属性分组'),
        widthHeight:['800px','500px']
      }
    },
    methods:{
      i18n(name,text,key){
            return this.$ti18(name,text,"osPropertiesGroup",key);
      },
      delById(ids){
        return osPropertiesGroupApi.del({ ids: ids.join(',') });
      },
      getListByParams(parameter){
        return osPropertiesGroupApi.query(parameter)
      },
      selectItem(e){
        if(e.key=='0'){
          this.isGroup=true;
        }else {
          this.isGroup=false;
        }
        var self=this;
        var conf = {
          curVm: self,
          component: osPropertiesGroupEdit,
          title: this.i18n('list.customAttrGroup','自定义属性分组'),
          widthHeight: ['800px', '500px'],
          data:{isGroup:this.isGroup},
        };
        Util.open(conf, function (action) {
          if (action != "ok") {
            return;
          }
          self.$refs.table.loadData();
        });
      },
      edit(record){
        if(record.dimId=="-1"){
          this.isGroup=false;
        }else {
          this.isGroup=true;
        }
        var conf={
          pkId:record.pkId,
          component:this.component,
          title:this.$ti18('rxList.editBtn','编辑') + this.comment,
        };
        this.handleEdit(conf);
      },
      editOne(){
        var conf={
          component:this.component,
          title:this.$ti18('rxList.editBtn','编辑') +this.comment,
        };
        if(this.selectedRows.length>0){
          if(this.selectedRows.length>1){
              this.$message.warning(this.i18n('cannotEdit','选中多条记录时不能编辑'));
            return;
          }
          if(this.selectedRows[0].dimId=="-1"){
            this.isGroup=false;
          }else {
            this.isGroup=true;
          }
          conf.pkId=this.selectedRows[0].pkId;
          this.handleEdit(conf)
        }
      },
      handleEdit (conf) {
        var pk=conf.pkId;
        var self_=this;
        var baseConf= {
          "curVm":self_,
          "data":{"pkId":pk,isGroup:this.isGroup,callback:function(data){
              console.info(data);
            }}
        };
        let config = Object.assign(baseConf, conf);
        if(!this.widthHeight){
          config.max=true;
        }
        else{
          config.widthHeight=this.widthHeight
        }
        Util.open(config,function(action){
          if(action=="ok"){
            self_.refreshGrid();
          }
        });
      },
       search(){
         this.$refs.table.loadData();
      },
      cancel(){
        this.resetSearch();
      },
      closeSearchbar(){
        //关闭过滤弹窗；（点击X触发）
        this.fitSearch = false ;
      },
    }
  }
</script>
<style scoped>


</style>

